<%@ page language="java" import="java.util.*"  contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath %>">
<title>订单管理</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<%-- 引用layui.css --%>
<link rel="stylesheet" type="text/css" href="<%=basePath %>js/layui/css/layui.css" />
<link rel="stylesheet" type="text/css"href="<%=basePath %>css/common.css" />
</head>
<body>
	<div class="ibox">
		<div class="ibox-content bodycss">
			<!-- 表单搜索 开始 -->
		 	<section class="panel panel-padding ">
			<form class="layui-form layui-form-pane form-search"
				onsubmit="return false" method="get">
				<div class="layui-form-item layui-inline">
					<label class="layui-form-label">商品名称</label>
					<div class="layui-input-inline">
						<input name="goodsName" id="goodsName" value="" placeholder="请输入商品名称"
							class="layui-input">
					</div>
				</div>	
				<div class="layui-form-item layui-inline">
					<button class="layui-btn layui-btn-primary" lay-submit lay-filter="seach">
						<i class="layui-icon"></i> 搜 索
					</button>
				</div>
			</form>
			</section>
			<!-- 表单搜索 结束 -->
			<section class="panel panel-padding ">
			
			
			
				<div class="ibox-toolbar">
					<button id="confirm" 
					data-field="delete" 
					data-action="" 
					class="layui-btn layui-btn-sm layui-btn-danger">
					<i class="layui-icon">&#xe640;</i>采购商品确认
		          	</button>					
				</div>
			<table class="layui-table"  lay-filter="test"
				lay-data="{
	                        id: 'menuTeble',
	                        width:'auto',
	                        url: 'CGDH/queryList.do',
	                        page: true,
	                        even: true,
	                        skin: 'row',
	                        limits:[10,20,30,40,50],
	                        limit:10,
	                        method:'post'
	                        }"
				lay-filter="popedomLay">
				<thead>
					<tr>
						<th lay-data="{checkbox:true,disabledKey:'check_status',disabledKeyValue:'1,2'}"></th>
						<th lay-data="{field:'purchaseGoodsId', width:100}">序号</th>
						<th lay-data="{field:'purchaseId', width:150,align:'center'}">采购单号</th>
						<th lay-data="{field:'goodsName', width:120,align:'center'}">商品名称</th>
						<th lay-data="{field:'specifications', width:120,align:'center'}">规格</th>
						<!-- <th lay-data="{field:'specId', width:200,align:'center'}">规格</th> -->
						<th lay-data="{field:'statu', width:120,align:'center',templet:'#m_type'}">状态</th>
						<th lay-data="{field:'number', width:120,align:'center'}">采购数量</th>
						<th lay-data="{field:'realNum', width:120,align:'center'}">实际到货数量</th>
						<th lay-data="{field:'createTime', width:160,align:'center'}">创建时间</th>
					</tr>
				</thead>
			</table>
			</section>
		</div>
	</div>
	
	<script type="text/html" id="m_type">	
	    {{#  if(d.statu == "0") {  }}
			<font color="#ff0000">未到货</font>
		{{#  } else if(d.statu == "1") {  }}
			<font color="#00ff00">已到货</font>
         {{#  } else if(d.statu == "2") {  }}
			<font color="#ff0000">申请退货</font>
		{{#  } else if(d.statu == "3") {  }}
			<font color="#ff0000">已退货</font>
		{{#  }  }}
    </script>
	
	<script type="text/javascript" src="<%=basePath %>js/layui/layui.js"></script>
	<script type="text/javascript">
	layui.config({
	    base: "<%=basePath%>/js/common/"
	}).use(["common", "element", "layer", "form", "table", "jquery"], function(){
			var elem = layui.element;
			var layer = layui.layer;
			var form = layui.form;
			var table = layui.table;
			var $ = layui.jquery;
			layui.common.init();

			/**
			 *	 监听刷新表格
			  
			 */
		form.on('submit(seach)', function(data){
		
			table.reload('menuTeble', {
				where: data.field,
				page : {
					curr : 1
				}
			});
			return false;
		});
		// 确认按钮
		$("#confirm").on("click", function(){
			var s = table.checkStatus('menuTeble');
			console.log(s.data[0].realNum);
			if(s.data.length <= 0){
				layer.msg("请选择要确认的订单", {icon: 3,time: 2000});
				return;
			}
			if(s.data.length > 1){
				layer.msg("请选择一条要确认的订单", {icon: 3,time: 2000});
				return;
			}
			if(s.data[0].realNum >0  ){
				layer.msg("已确认的订单，请勿重复确认！", {icon: 3,time: 2000});
				return;
			}
			var sid = "";
		 	var id="";
			for(var i = 0; i < s.data.length;i++){
				sid += s.data[i].purchaseId;
				 id += s.data[i].purchaseGoodsId; 
			}
			layer.open({
				type: 2,	
                title: "采购商品确认",
                content : "CGDH/toConfirm.do?purchaseId="+sid+"&purchaseGoodsId="+id,
              
                area: ['800px', '650px'],
                anim: 5,
                isOutAnim: true,
                maxmin: true,
                resize: false,
                moveOut: true,
                zIndex: 99999,
                success: function(layero, index){
                	var body = layer.getChildFrame('body', index);
                    body.contents().find("INPUT[name='purchaseGoodsId']").val(s.data[0].purchaseGoodsId);
                    body.contents().find("INPUT[name='purchaseId']").val(s.data[0].purchaseId);
                    body.contents().find("INPUT[name='goodsName']").val(s.data[0].goodsName);
                    body.contents().find("INPUT[name='number']").val(s.data[0].number); 
                    body.contents().find("INPUT[name='areaName']").val(s.data[0].areaName);
                },
                end : function(){
                	table.reload("menuTeble");
                }
            });
		
	});
});
</script>
</body>
</html>
